<?php $this->pageTitle = 'Payment Voucher #' . $paymentVoucher->payment_number; ?>
<?php
$this->breadcrumbs = array(
	'Payment Vouchers' => array('/paymentVoucher/index'),
	'#' . $paymentVoucher->payment_number
);
?>
<div class="main-title no-border clearfix">
	<h1 class="float-left">Payment Voucher #<?php echo $paymentVoucher->payment_number; ?></h1>
	<?php if ($paymentVoucher->deleted == 0): ?>
		<div class="controls">
			<a class="link-button with-icon" href="<?php echo $this->createUrl('/paymentVoucher/update', array('id' => $paymentVoucher->id)); ?>">
				<img src="/images/icons/fugue/pencil.png" />
				Edit
			</a>
			<a class="link-button with-icon" href="<?php echo $this->createUrl('/paymentVoucher/print', array('id' => $paymentVoucher->id)); ?>" target="_blank">
				<img src="/images/icons/fugue/printer.png" />
				Print Payment Voucher
			</a>
			<?php if (Yii::app()->user->model->agency->settings['Commission']['AutosetIssuedDate'] == 0) : ?>
				<?php if (!$paymentVoucher->isCollected()): ?>
					<a class="link-button with-icon" href="<?php echo $this->createUrl('/paymentVoucher/mark', array('id' => $paymentVoucher->id, 'collectedStatus' => 1)); ?>">
						<img src="/images/icons/farmfresh/16x16/accept.png" />
						Mark as Collected
					</a>
				<?php else: ?>
					<a class="link-button with-icon" href="<?php echo $this->createUrl('/paymentVoucher/mark', array('id' => $paymentVoucher->id, 'collectedStatus' => 0)); ?>">
						<img src="/images/icons/farmfresh/16x16/stop.png" />
						Mark as Uncollected
					</a>
				<?php endif; ?>
			<?php endif; ?>
		</div>
	<?php else: ?>
		<h1 class="float-left red pad">(Canceled)</h1>
	<?php endif; ?>
	<?php if ($paymentVoucher->deleted == 0): ?>
		<div class="controls float-right">
			<a class="link-button with-icon" href="<?php echo $this->createUrl('/paymentVoucher/delete', array('id' => $paymentVoucher->id)); ?>">
				<img src="/images/icons/fugue/cross-circle.png" />
				Cancel Payment Voucher
			</a>
		</div>
	<?php endif; ?>
</div>
<div class="flat_area">
    <div id="ps-payment-create" class="relative">
		<script type="text/javascript">
			var currency_code = "$";
		</script>
		<div id="payment-voucher-info" class="">
			<div class="grid_11">
				<div class="section">
					<div class="block">
						<h2>Payment Voucher Information</h2>
						<div class="table-block">
							<?php
							$this->widget('zii.widgets.CDetailView', array(
								'data' => $paymentVoucher,
								'nullDisplay' => '-',
								'attributes' => array(
									array(
										'name' => 'payee_name',
									),
									array(
										'name' => 'payment_method_type_code',
										'value' => $paymentVoucher->getPaymentMethod(),
									),
									'payment_ref_no',
									'comment',
								),
							));
							?>
						</div>
					</div>
				</div>
			</div>
			<div class="grid_5">
				<div class="section highlighted">
					<div class="block">
						<?php
						$this->widget('zii.widgets.CDetailView', array(
							'data' => $paymentVoucher,
							'attributes' => array(
								array(
									'label' => 'Payment Voucher #',
									'value' => $paymentVoucher->payment_number
								),
								array(
									'label' => 'Reason for canceling',
									'type' => 'raw',
									'value' => $paymentVoucher->delete_reason,
									'visible' => $paymentVoucher->deleted
								),
								array(
									'name' => 'payment_date',
									'type' => 'raw',
									'value' => Yii::app()->dateFormatter->formatDateTime(strtotime($paymentVoucher->payment_date), "short", null)
								),
								array(
									'label' => 'Amount',
									'value' => Yii::app()->numberFormatter->formatCurrency($paymentVoucher->amount, $paymentVoucher->currency_code)
								),
								array(
									'label' => 'Collected?',
									'value' => $paymentVoucher->issued_date ? 'Yes' : 'No',
								),
								array(
									'name' => 'issued_date',
									'value' => Yii::app()->dateFormatter->formatDateTime($paymentVoucher->issued_date, "short", null),
								),
							),
							'htmlOptions' => array('class' => 'summary-table')
						));
						?>
					</div>
				</div>
			</div>
			<div id="payable_items" class="grid_16">
				<div class="section">
					<div class="block">
						<h2>Payable Voucher Detail</h2>
						<?php
						$this->widget('PsGridView', array(
							'id' => 'payable_items_grid',
							'dataProvider' => $this->getPaymentDetailsDataProvider($id, $from_date, $to_date, $paymentVoucher->id),
							'template' => '{pager}{items}',
							'pagesizeCssClass' => 'pager-pagesize',
							'itemsCssClass' => 'items clear',
							'emptyText' => 'No payable items found.',
							'selectableRows' => 0,
							'htmlOptions' => array(
								'class' => 'grid-view grey',
							),
//						'afterAjaxUpdate' => 'prestige.payment.update.onGridViewUpdate',
							'columns' => array(
								array(
									'header' => 'Date Created',
									'name' => 'create_time',
									'type' => 'raw',
									'value' => '(date("d-m-Y", strtotime($data->create_time)))',
									'htmlOptions' => array(
										'width' => 100
									)
								),
								array(
									'header' => 'Commission Type',
									'name' => 'comm_type',
									'type' => 'raw',
									'value' => '(ucfirst($data->comm_type))',
									'htmlOptions' => array(
										'width' => 100
									)
								),
								array(
									'header' => 'Description',
									'name' => 'description',
									'type' => 'raw',
									'value' => '$data->description',
									'htmlOptions' => array(
										'width' => '*'
									)
								),
								'case_number' => array(
									'header' => 'Related Transactions',
									'class' => 'common.widgets.grid.PsPartialViewColumn',
									'view' => '_column_case_number',
									'htmlOptions' => array(
										'class' => 'valign-top',
									)
								),
								array(
									'header' => 'Related Receipt',
									'name' => 'payment_number',
									'type' => 'raw',
									'value' => 'CHtml::link("#" . $data->payment->payment_number, array("receipt/view", "id" => $data->payment->id), array("class" => "blue link"))',
									'htmlOptions' => array(
										'width' => 130
									)
								),
								array(
									'header' => 'Receipt Date',
									'name' => 'payment_date',
									'type' => 'raw',
									'value' => 'Yii::app()->dateFormatter->formatDateTime(strtotime($data->payment->payment_date), "short", null)',
									'htmlOptions' => array(
										'width' => 130
									)
								),
								array(
									'header' => 'Amount',
									'name' => 'net_amount',
									'type' => 'raw',
									'value' => 'Yii::app()->numberFormatter->formatCurrency($data->net_amount, "$ ")',
									'headerHtmlOptions' => array('class' => 'align-right'),
									'htmlOptions' => array(
										'width' => 100,
										'class' => 'align-right'
									)
								),
							)
						));
						?>
					</div>
				</div>
			</div>
		</div>
    </div>
</div>


